<?php

namespace Sock;

class SocketHandler{
    public $client;
    
    public function __construct($client){
        $this->client = $client;
    }
    
    public function onConnect(){
        $this->client->send("Welcome!\n*>");
    }
    
    public function onReceiveData($msg=''){
        if(trim(substr($msg, 0, 6)) == 'shout '){
            $this->client->send("\n*>");
            $this->client->broadcast(substr($msg, 6));
        }else{
            $this->client->send("You said: ".$msg."\n*>");
        }
    }
    
    public function onQuit(){
        $this->client->send("Goodbye!\n\n");
    }
    
    public function onDisconnect(){}
}